package com.cloudcc.mobile.dao.impl;

import java.util.List;

import com.cloudcc.cloudframe.net.RequestListener;
import com.cloudcc.cloudframe.net.async.EventRequest;
import com.cloudcc.cloudframe.net.async.JsonObjectRequest;
import com.cloudcc.mobile.AppConstant;
import com.cloudcc.mobile.dao.AttendanceEngine;
import com.cloudcc.mobile.dao.BaseEngine;
import com.cloudcc.mobile.entity.AttendanceEntity;
import com.cloudcc.mobile.event.AttendanceEventList.AttendanceHomeEvent;
import com.cloudcc.mobile.event.AttendanceEventList.AttendanceListEvent;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.manager.UrlManager;
import com.cloudcc.mobile.presenter.AttendancePresenter.AttendanceHomeEntity;
import com.loopj.android.http.RequestParams;

public class AttendanceEngineImpl extends BaseEngine implements
		AttendanceEngine {

	@Override
	public void attendance(String serveiceName, String lng, String lat,
			String type, String position, RequestListener li) {
		RequestParams params = new RequestParams();
		params.put("serviceName", serveiceName);
		params.put("lng", lng);
		params.put("lat", lat);
		params.put("type", type);
		params.put("position", position);
		params.put("binding", RunTimeManager.getInstance().getServerBinding());
		JsonObjectRequest request = new JsonObjectRequest();
		request.setRequestListener(li);
		sendPost(UrlManager.getInterfaceUrl(), params, request);
	}

	@Override
	public void getAttendanceHistory(int pageNum, AttendanceListEvent event) {
		EventRequest<List<AttendanceEntity>> request = new EventRequest<List<AttendanceEntity>>(){};
		request.setEvent(event);
		RequestParams params = new RequestParams();
		params.put("pageNUM", pageNum);
		params.put("pageSize",AppConstant.PAGE_SIZE);
		sendPost(params, "checkHistory", request);
	}

	@Override
	public void getAttendanceHome(AttendanceHomeEvent event) {
		EventRequest<AttendanceHomeEntity> request = new EventRequest<AttendanceHomeEntity>(){};
		request.setEvent(event);
		RequestParams params = new RequestParams();
		sendPost(params, "checkinHome", request);
	}

}
